package leetcodecompetition.D371;

import java.util.*;

/**
 * @Author: Siantar
 * @Date: 2023-11-12-10:49
 * @Description: 1.0
 */
public class T100128 {
    public List<String> findHighAccessEmployees(List<List<String>> access_times) {
        List<String> res = new ArrayList<>();
        access_times.sort((a, b) -> Integer.parseInt(a.get(1)) - Integer.parseInt(b.get(1)));
        Map<String, Integer> map = new HashMap<>();
        LinkedList<List<String>> lists = new LinkedList<>();
        for (List<String> at : access_times) {
            String access = at.get(0);
            String times = at.get(1);
            System.out.println(access + times);
            while (!lists.isEmpty() && Integer.parseInt(times) - Integer.parseInt(lists.getFirst().get(1)) >= 1) {
                String a = lists.pollFirst().get(0);
                map.put(a, map.get(a) - 1);
                System.out.println("---" + a);
            }
            lists.offerLast(at);
            int f = map.getOrDefault(access, 0);
            if (f + 1 >= 3 && !res.contains(access)) {
                res.add(access);
            }
            map.put(access, f + 1);
            System.out.println(access + "    times" + f + 1);
        }
        return res;
    }
}
